const qiniu = require('qiniu')

const accessKey = 'WYh-Bd0FntiwSR4B7PloBBS8WFDl3TKRsOW1QuTH';
const secretKey = 'Bl4VSSgr-mmocRgDztcnbDO_8ZDOFZe7MNQGr160';

// 根据你的key值分配了一个钥匙
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey);


function getToken({ url, scope }) {
    var options = {
        scope, // 上传的空间名称
        expires: 3600 * 24 * 365, // 过期的时间
        returnBody: `{"url":"${url}/$(key)","code":0}`,
    };

    let putPolicy = new qiniu.rs.PutPolicy(options);

    return putPolicy.uploadToken(mac);
}


module.exports = getToken;